<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
include_once '../../connection/connection_database.php';
include_once '../../language/vn.php';
include_once '../../language/url.php';

if (isset($_POST)) {
    $arrUrl = explode("/", $url["home"]);
    $url = "/".$arrUrl[1]."/".$arrUrl[2];
    
    $sql = "SELECT * FROM users WHERE user_name='{$_POST["username"]}'";
    $query = mysql_query($sql) or die(mysql_error());
    $fillByName = mysql_fetch_array($query);
    $level_decode = json_decode($fillByName["level"], true);
    
    $sql = "SELECT * FROM cate_board_page c, cate_board cb WHERE c.board_id=cb.board_id and c.board_id = '" . $_POST["id"] . "' ";
    $result = mysql_query($sql) or die(mysql_error());
}
?>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    <thead>
        <tr>
            <th width="35%"><?php echo $phrase["page_title"] ?></th>
            <th width="15%"><?php echo $phrase["page_tacgia"] ?></th>
            <th width="35%"><?php echo $phrase["page_summary"] ?></th>
            <th width="15%"><?php echo $phrase["page_date"] ?></th>
            <td class="status" width="8%"></td>
        </tr>
    </thead>
    <tbody>
        <?php
        while ($rows = mysql_fetch_array($result)) {
            $date = new DateTime($rows["page_date"]);
            ?>
            <tr class="gradeC">
                <td><?php echo $rows["page_title"] ?></td>
                <td><?php echo $rows["user_fullname"] ?></td>
                <td><?php echo $rows["page_summary"] ?></td>
                <td><?php echo $date->format('d/m/Y') ?></td>
                <?php if ($i % 2) { ?>
                    <td class="first">
                        <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "") { ?>
                            <a href="<?= $url ?>/menu/pageupdate/t/2/id/<?php echo $rows["page_id"] ?>">
                                <image src="<?= $url ?>/images/icons/edit-icon.gif"/>
                            </a>
                        <?php } ?>
                        <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "" && $level_decode["delete"]) { ?>
                            | 
                        <?php } ?>
                        <?php if ($level_decode["admin"] != "" || $level_decode["delete"] != "") { ?>
                            <a href="<?= $url ?>/menu/pagedelete/t/2/trash/<?php echo $rows["page_id"] ?>" onclick="return confirm('Bạn có chắc chắn muốn xóa không.');">
                                <image src="<?= $url ?>/images/icons/b_drop.png"/>
                            </a>
                        <?php } ?>
                    </td>
                <?php } else { ?>
                    <td class="last">
                        <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "") { ?>
                            <a href="<?= $url ?>/menu/pageupdate/t/2/id/<?php echo $rows["page_id"] ?>">
                                <image src="<?= $url ?>/images/icons/edit-icon.gif"/>
                            </a>
                        <?php } ?>
                        <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "" && $level_decode["delete"]) { ?>
                            | 
                        <?php } ?> 
                        <?php if ($level_decode["admin"] != "" || $level_decode["delete"] != "") { ?>
                            <a href="<?= $url ?>/menu/pagedelete/t/2/trash/<?php echo $rows["page_id"] ?>" onclick="return confirm('Bạn có chắc chắn muốn xóa không.');">
                                <image src="<?= $url ?>/images/icons/trash_1.png"/>
                            </a>
                        <?php } ?>
                    </td>
                <?php } ?>
            </tr>
        <?php } ?>
    </tbody>
    <tfoot>
        <tr>
            <th colspan="5"></th>
        </tr>
    </tfoot>
</table>
<script type="text/javascript">
    $(document).ready(function() {
        $('#example').dataTable({
            "aaSorting": [[ 3, "desc" ]],
            "sPaginationType": "full_numbers"
        });
    });
</script>